package com.itjason.exceptionhandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * Author:JasonLong
 * Date:2023/5/11
 * Time:16:53
 * 全局异常处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    //定义调试日志
    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    //自定义异常处理
    @ExceptionHandler(CustomException.class)
    public ResponseException customException(CustomException e) {
        return ResponseException.error(e.getErrorCode(), e.getErrorMsg());
    }

    //空指针异常
    @ExceptionHandler(NullPointerException.class)
    public ResponseException nullPointException() {
        return ResponseException.error(EnumException.NULL_POINT.getResultCode(), EnumException.NULL_POINT.getResultMsg());
    }
}
